package org.red5.conf;

import org.red5.websocket.STOMPConnectEventListener;
import org.red5.websocket.SocketSessionRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 *  
 *  * @projectName videoservice
 *  * @title     WebSocketConfig   
 *  * @package    com.de.config  
 *  * @description    开启websocket支持
 *  * @author IT_CREAT     
 *  * @date  2020 2020/4/12 0012 下午 16:39  
 *  * @version V1.0.0 
 *  
 */
//@Configuration
//public class WebSocketConfig {
//
//    @Bean
//    public ServerEndpointExporter serverEndpointExporter() {
//        return new ServerEndpointExporter();
//    }
//}


/**
 * @ClassName WebSocketConfig
 * @Description //通过EnableWebSocketMessageBroker 开启使用STOMP协议来传输基于代理(message broker)的消息,此时浏览器支持使用@MessageMapping 就像支持@RequestMapping一样。
 * @Author 武玉锋
 * @Date 2019-07-25 16:42:
 **/
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {



    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) { //endPoint 注册协议节点,并映射指定的URl
        //注册一个名字为"endpointSockJS" 的endpoint,并指定 SockJS协议。   点对点-用
        registry.addEndpoint("/endpointSockJS").setAllowedOrigins("*").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {//配置消息代理(message broker)
        //点对点式增加一个/queue 消息代理
        registry.enableSimpleBroker("/queue", "/topic");

    }

    @Bean
    public SocketSessionRegistry SocketSessionRegistry(){
        return new SocketSessionRegistry();
    }
    @Bean
    public STOMPConnectEventListener STOMPConnectEventListener(){
        return new STOMPConnectEventListener();
    }

}

